<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收货作业列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="status" name="status" th:value="2"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 85px">入库单编号：</label>
                            <input type="text" name="orderCode"/>
                        </li>
                        <li>
                            <label>订单号：</label>
                            <input type="text" name="orderName"/>
                        </li>
                        <li>
                            <label>订单日期：</label>
                            <input type="text" class="time-input" placeholder="请选择订单日期" name="orderDate"/>
                        </li>
                        <li>
                            <label style="width: 85px">单位名称：</label>
                            <input type="text" name="desWarehouseName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a id="toDischarge" class="btn btn-primary" onclick="onToDischarge()" shiro:hasPermission="wh:warehousingOrder:editDischarge">
                 待卸货
            </a>
            <a id="forsorting" class="btn btn-default" onclick="onForsorting()" shiro:hasPermission="wh:warehousingOrderSeed:editComplete">
                 待分拣
            </a>
            <a id="complete" class="btn btn-default" onclick="onComplete()" shiro:hasPermission="wh:warehousingOrderSeed:editCompleteSave">
                 已分拣(入库)
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editDischargeFlag = [[${@permission.hasPermi('wh:warehousingOrder:editDischarge')}]];
    var editRemoveFlag = [[${@permission.hasPermi('wh:warehousingOrder:editRemove')}]];
    var editCompleteFlag = [[${@permission.hasPermi('wh:warehousingOrderSeed:editComplete')}]];
    var editCompleteSaveFlag = [[${@permission.hasPermi('wh:warehousingOrderSeed:editCompleteSave')}]];
    var prefix = ctx + "wh/warehousingOrder";
    var orderSeedPrefix = ctx + "wh/warehousingOrderSeed";
    $(function() {
        //先判断各按钮权限由右做右依次顺序，有权限项赋值状态给初始化table
        if($.common.isEmpty(editDischargeFlag)){
            $('#status').val('2')
        }else if($.common.isEmpty(editCompleteFlag)){
            $('#status').val('3')
            $('#forsorting').removeClass();
            $('#forsorting').attr('class',"btn btn-primary");
            $('#toDischarge').removeClass();
            $('#toDischarge').attr('class',"btn btn-default");
            $('#complete').removeClass();
            $('#complete').attr('class',"btn btn-default");
        }else if($.common.isEmpty(editCompleteSaveFlag)){
            $('#status').val('4')
            $('#complete').removeClass();
            $('#complete').attr('class',"btn btn-primary");
            $('#toDischarge').removeClass();
            $('#toDischarge').attr('class',"btn btn-default");
            $('#forsorting').removeClass();
            $('#forsorting').attr('class',"btn btn-default");
        }

        var options = {
            url: prefix + "/list",
            modalName: "入库单",
            sortName: "createTime",
            sortOrder: "desc",
            queryParams: queryParams,
            detailView: true,
            onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [
                {
                checkbox: true
                 },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'orderCode',
                    title: '入库单编号'
                },
                {
                    field: 'orderTypeDesc',
                    title: '单据类型'
                },
                {
                    field: 'orderName',
                    title: '订单号'
                },
                {
                    field: 'orderDate',
                    title: '订单日期'
                },
                {
                    field: 'desWarehouseName',
                    title: '交易单位名称'
                },
                {
                    field: 'rate',
                    title: '税率'
                },
                {
                    field: 'tax',
                    title: '税额'
                },
                {
                    field: 'discountRate',
                    title: '折扣率'
                },
                {
                    field: 'discountAmount',
                    title: '折扣金额'
                },
                {
                    field: 'discountPrice',
                    title: '折让金额'
                },
                {
                    field: 'otherFee',
                    title: '其他费用'
                },
                {
                    field: 'untaxedAmount',
                    title: '未税金额'
                },
                {
                    field: 'totalAmount',
                    title: '含税金额'
                },
                {
                    field: 'statusDesc',
                    title: '状态'
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == '2'){
                            actions.push('<a class="btn btn-success btn-xs ' + editDischargeFlag + '" href="javascript:void(0)" onclick="editStauts(\'' + row.id + '\')">确认卸货完成</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + editRemoveFlag + '" href="javascript:void(0)" onclick="editRemove(\'' + row.id + '\')">作废</a>');
                        }else if(row.status == '3'){
                            actions.push('<a class="btn btn-success btn-xs ' + editCompleteFlag + '" href="javascript:void(0)" onclick="editComplete(\'' + row.id + '\')">确认分拣完成</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        /********子视图***********/
        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: orderSeedPrefix + "/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    warehousingOrderId: row.id
                },
                columns: [{
                    field : 'id',
                    title : 'id',
                    visible: false
                     },
                    {
                        field: 'shopGoodsCode',
                        title: '商品名称'
                    },
                    {
                        field: 'shopGoodsName',
                        title: '商品名称'
                    },
                    {
                        field: 'goodsUnitDesc',
                        title: '单位描述'
                    },
                    {
                        field: 'planNumber',
                        title: '计划数量'
                    },
                    {
                        field: 'warehousingNumber',
                        title: '实际数量'
                    },
                    {
                        field: 'moreNumber',
                        title: '多到货数量'
                    },
                    {
                        field: 'shortageNumber',
                        title: '到货短少数量'
                    },
                    {
                        field: 'taxUnitPrice',
                        title: '含税单价'
                    },
                    {
                        field: 'untaxedAmount',
                        title: '未税金额'
                    },
                    {
                        field: 'amount',
                        title: '含税金额'
                    }]
            });
        };

    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.status = $('#status').val();
        return search;
    }

    /****待卸货*****/
    function onToDischarge(){
        $('#status').val('2')
        //改变按钮样式
        $('#toDischarge').removeClass();
        $('#toDischarge').attr('class',"btn btn-primary");
        $('#forsorting').removeClass();
        $('#forsorting').attr('class',"btn btn-default");
        $('#complete').removeClass();
        $('#complete').attr('class',"btn btn-default");
        $.table.refresh();
    }
    /****待分拣*****/
    function onForsorting(){
        $('#status').val('3')
        $('#forsorting').removeClass();
        $('#forsorting').attr('class',"btn btn-primary");
        $('#toDischarge').removeClass();
        $('#toDischarge').attr('class',"btn btn-default");
        $('#complete').removeClass();
        $('#complete').attr('class',"btn btn-default");
        $.table.refresh();
    }
    /****已分拣(完成)*****/
    function onComplete(){
        $('#status').val('4')
        $('#complete').removeClass();
        $('#complete').attr('class',"btn btn-primary");
        $('#toDischarge').removeClass();
        $('#toDischarge').attr('class',"btn btn-default");
        $('#forsorting').removeClass();
        $('#forsorting').attr('class',"btn btn-default");
        $.table.refresh();
    }

    /*******更改状态确认是否已卸货*********/
    function editStauts(id){
        $.modal.confirm("确认卸货完成。", function() {
            $.operate.post(prefix + "/editDischarge", { "id": id, "status": '3' });
        })
    }

    /*******确认分拣完成*********/
    function editComplete(id){
        var url = orderSeedPrefix + '/editComplete/'+id;
        $.modal.open("分拣(入库)", url);
    }

    /*******作废*********/
    function editRemove(id){
        $.modal.confirm("确认作废。", function() {
            $.operate.post(prefix + "/editRemove", { "id": id });
        })
    }
</script>
</body>
</html>